/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 * Description: 性能评估器相关头文件
 * Author: sunzhepeng
 * Create: 2022-8-1
 */

#ifndef HOCKNEY_MODEL_H
#define HOCKNEY_MODEL_H

#include <cmath>
#include <limits>
#include "graph_common_def.h"
#include "dtype_common.h"

namespace HcclEvaluator {

// α is the latency (or startup time) per transmit
// β is the transfer time per byte
// γ is the reduce time per byte
struct HockneyModelParam {
    float alpha;
    float beta;
    float gamma;
};

class HockneyModel {
public:
    explicit HockneyModel(HockneyModelParam param);
    ~HockneyModel() = default;
    float CalcCost(u32 nodeNum, u64 byteNum, SubgraphOpType op, AlgType alg);
private:
    bool CheckPower2(u32 num);
    float CalcLog2(u32 num);
    float CalcFloorLog2(u32 num);
    float CalcCeilLog2(u32 num);
    float CalcFloorPower2(u32 num);

    float CalcPairWiseCost(u32 nodeNum, u64 byteNum, SubgraphOpType op);
    float CalcRingCost(u32 nodeNum, u64 byteNum, SubgraphOpType op);
    float CalcMeshCost(u32 nodeNum, u64 byteNum, SubgraphOpType op);
    float CalcHalvingDoublingCost(u32 nodeNum, u64 byteNum, SubgraphOpType op);
    float CalcHalvingDoublingCostPower2(u32 nodeNum, u64 byteNum, SubgraphOpType op);
    float CalcHalvingDoublingCostNonPower2(u32 nodeNum, u64 byteNum, SubgraphOpType op);

    float alpha_;
    float beta_;
    float gamma_;
};

}
#endif